[アップデート] Amazon Inspector SBOM Generator が Dockerfile の設定不備を検出するようになりました #AWSreInforce

[アップデート] Amazon Inspector SBOM Generator が Dockerfile の設定不備を検出するようになりました #AWSreInforce

Amazon Inspector SBOM Generator が Dockerfile の設定不備を検出するようになりました。 Inspector Scan API を利用して詳細を確認できます。
Clock Icon2024.06.13

こんにちは! AWS 事業本部コンサルティング部のたかくに(@takakuni_)です。普段は趣味で Amazon Inspector の追っかけをしています。

フィラデルフィアで開催されている AWS re:Inforce 2024 に参加しています。

Keynote や What's new の裏側で Amazon Inspector SBOM Generator が Dockerfile の設定不備を検出するようになりました。

Updated functionality
The Amazon Inspector SBOM Generator now scans Dockerfiles and Docker container images for misconfigurations that can introduce security vulnerabilities. For more information, see Amazon Inspector Dockerfile checks.
June 10, 2024

Document history for the Amazon Inspector User Guide - Amazon Inspector

Amazon Inspector SBOM Generator については以下をご覧ください。

Inspector のコンテナイメージスキャンを CodeBuild で実行してみた #AWSreInvent | DevelopersIO

何が変わったのか

端的に言いますと先ほどの通りで、Amazon Inspector SBOM Generator が Dockerfile の設定不備を検出するようになりました。

もう少し深掘りすると、以下の 2 つの場面において Dockerfile の設定不備をスキャンし SBOM に登録するようになりました。

  • コンテナイメージ内の Dockerfile
  • Docckerfile を含むディレクトリ or Dockerfile 本体をターゲットにした場合

検出項目

リリース時点での検出項目は以下のとおりです。

  • sudo のバイナリが含まれる
  • 複数行の apt-get を実行している
  • 認証情報がハードコードされている
  • 特権モードで実行している
  • 各ランタイムでの脆弱な環境変数の設定
  • 各ランタイムでの脆弱なコマンドフラグの設定

詳しくは以下をご覧ください。

Amazon Inspector Dockerfile checks - Amazon Inspector

やってみる

簡単にですが Amazon Inspector SBOM Generator で Dockerfile のスキャンをして見ます。

Amazon Linux 2023 を用意して以下のコマンドを使ってインストールしていきます。

sudo su -

# ARM と AMD でパスが違う
curl -O "https://amazon-inspector-sbomgen.s3.amazonaws.com/latest/linux/arm64/inspector-sbomgen.zip"

unzip inspector-sbomgen.zip
mv inspector-sbomgen-* inspector-sbomgen-latest

chmod +x inspector-sbomgen-latest/linux/arm64/inspector-sbomgen
./inspector-sbomgen-latest/linux/arm64/inspector-sbomgen --version

dnf install -y docker
service docker start

Dockerfile の準備

Dockefile は以下を使います。明示的に root ユーザーを使っているよう指定します。

app/Dockerfile
FROM public.ecr.aws/docker/library/python:3.10-slim
USER root
COPY requirements.txt /root/
RUN pip3 install --no-cache-dir -r /root/requirements.txt

requirements.txt は簡単に以下を用意しました。

app/requirements.txt
boto3==1.34.125

コマンドを実行してみる

それでは Dockerfile のスキャンを行なって見ます。

./inspector-sbomgen-latest/linux/arm64/inspector-sbomgen directory --path app/ --outfile /tmp/sbom.json --quiet

中身をのぞいてみると SBOM ファイルの中に Dockerfile の情報が含まれてますね。 type が file のものが該当しそうです。

/tmp/sbom.json
{
	"bomFormat": "CycloneDX",
	"specVersion": "1.5",
	"serialNumber": "urn:uuid:43d83b26-2707-4ecb-b493-cce8514cc451",
	"version": 1,
	"metadata": {
		"timestamp": "2024-06-13T07:28:16Z",
		"tools": {
			"components": [
				{
					"type": "application",
					"author": "Amazon Web Services, Inc. (AWS)",
					"name": "inspector-sbomgen",
					"version": "1.2.0",
					"hashes": [
						{
							"alg": "SHA-256",
							"content": "eaaa273cb3796e764ac8bae485e62160052d5fee5f0e4d21fde8f21dbfbcd513"
						}
					]
				}
			]
		},
		"component": {
			"bom-ref": "comp-1",
			"type": "file",
			"name": "/root/app"
		}
	},
	"components": [
		{
			"bom-ref": "comp-2",
			"type": "library",
			"name": "boto3",
			"version": "1.34.125",
			"purl": "pkg:pypi/boto3@1.34.125",
			"properties": [
				{
					"name": "amazon:inspector:sbom_generator:source_path",
					"value": "app/requirements.txt"
				}
			]
		},
		{
			"bom-ref": "comp-3",
			"type": "file",
			"name": "dockerfile:app/Dockerfile",
			"properties": [
				{
					"name": "amazon:inspector:sbom_generator:dockerfile_finding:IN-DOCKER-003",
					"value": "affected_lines:2-2"
				}
			]
		}
	]
}

Inspector Scan API を利用して SBOM ファイルから脆弱性を確認して見ます。

aws inspector-scan scan-sbom --sbom file:///tmp/sbom.json --output-format INSPECTOR --no-cli-pager

実行結果を確認すると IN-DOCKER-003 の ID で脆弱性が検出されていますね。

[root@ip-172-31-2-25 ~]# aws inspector-scan scan-sbom --sbom file:///tmp/sbom.json --output-format INSPECTOR --no-cli-pager
{
    "sbom": {
        "messages": [
            {
                "purl": "pkg:pypi/boto3@1.34.125",
                "info_message": "Component skipped: no rules found."
            }
        ],
        "vulnerabilities": [
            {
                "severity": "info",
                "references": [
                    "https://docs.docker.com/develop/develop-images/instructions/"
                ],
                "created": "2024-03-27T14:36:39Z",
                "description": "Last USER is root: If a service can run without privileges, use USER to change to a non-root user.",
                "affects": [
                    {
                        "file": "dockerfile:app/Dockerfile",
                        "lines": "2-2"
                    }
                ],
                "id": "IN-DOCKER-003",
                "source": "https://aws.amazon.com/inspector/",
                "updated": "2024-03-27T14:36:39Z",
                "properties": {}
            }
        ],
        "vulnerability_count": {
            "high": 0,
            "other": 1,
            "critical": 0,
            "low": 0,
            "medium": 0
        }
    }
}

コンテナイメージ

コンテナイメージのビルドを行なって、コンテナイメージからも Dockerfile のチェックを確認してみます。

docker image build -t sbom-target app/
./inspector-sbomgen-latest/linux/arm64/inspector-sbomgen container --image sbom-target:latest --outfile /tmp/sbom_from_image.json --quiet
aws inspector-scan scan-sbom --sbom file:///tmp/sbom_from_image.json --output-format INSPECTOR --no-cli-pager

コンテナイメージで使っている OS のスキャナーも働くため、先ほどより検出項目が多いですね。見たかったのは IN-DOCKER-003 ですが、コンテナイメージでもしっかり機能していることがわかります。

[root@ip-172-31-2-25 ~]# aws inspector-scan scan-sbom --sbom file:///tmp/sbom_from_image.json --output-format INSPECTOR --no-cli-pager
{
    "sbom": {
        "messages": [
            {
                "purl": "pkg:deb/debian/mawk@1.3.4.20200120-3.1?arch=arm64&distro=bookworm&epoch=0",
                "info_message": "Component skipped: no rules found."
            },
        ],
        "vulnerabilities": [
            {
                "severity": "low",
                "related": [
                    "GHSA-mq26-g339-26xf"
                ],
                "references": [
                    "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/622OZXWG72ISQPLM5Y57YCVIMWHD4C3U/",
                    "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/65UKKF5LBHEFDCUSPBHUN4IHYX7SRMHH/",
                    "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/YBSB3SUPQ3VIFYUMHPO3MEQI4BJAXKCZ/",
                    "https://mail.python.org/archives/list/security-announce@python.org/thread/F4PL35U6X4VVHZ5ILJU3PWUWN7H7LZXL/",
                    "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/KFC2SPFG5FLCZBYY2K3T5MFW2D22NG6E/",
                    "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/FXUVMJM25PUAZRQZBF54OFVKTY3MINPW/",
                    "https://alas.aws.amazon.com/AL2023/ALAS-2023-442.html",
                    "https://access.redhat.com/errata/RHSA-2024:3781",
                    "https://alas.aws.amazon.com/AL2/ALAS-2023-2349.html",
                    "https://www.cve.org/CVERecord?id=CVE-2023-5752"
                ],
                "created": "2023-10-25T18:17:44Z",
                "description": "When installing a package from a Mercurial VCS URL  (ie \"pip install \nhg+...\") with pip prior to v23.3, the specified Mercurial revision could\n be used to inject arbitrary configuration options to the \"hg clone\" \ncall (ie \"--config\"). Controlling the Mercurial configuration can modify\n how and which repository is installed. This vulnerability does not \naffect users who aren't installing from Mercurial.\n",
                "affects": [
                    {
                        "path": "/usr/local/lib/python3.10/site-packages/pip-23.0.1.dist-info/METADATA",
                        "fixed_version": "23.3",
                        "installed_version": "pkg:pypi/pip@23.0.1"
                    }
                ],
                "id": "CVE-2023-5752",
                "source": "https://nvd.nist.gov/vuln/detail/CVE-2023-5752",
                "updated": "2024-06-10T18:15:24Z",
                "properties": {
                    "epss": 0.00045,
                    "cwes": [
                        77
                    ],
                    "cvss": [
                        {
                            "severity": "low",
                            "cvss_3_base_score": 3.2999999523,
                            "cvss_3_base_vector": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N",
                            "source": "NVD"
                        }
                    ]
                }
            },
            {
                "severity": "info",
                "references": [
                    "https://docs.docker.com/develop/develop-images/instructions/"
                ],
                "created": "2024-03-27T14:36:39Z",
                "description": "Last USER is root: If a service can run without privileges, use USER to change to a non-root user.",
                "affects": [
                    {
                        "file": "dockerfile:comp-1.Dockerfile",
                        "lines": "3-3"
                    }
                ],
                "id": "IN-DOCKER-003",
                "source": "https://aws.amazon.com/inspector/",
                "updated": "2024-03-27T14:36:39Z",
                "properties": {}
            }
        ],
        "vulnerability_count": {
            "high": 1,
            "other": 3,
            "critical": 0,
            "low": 1,
            "medium": 4
        }
    }
}

まとめ

以上、「Amazon Inspector SBOM Generator が Dockerfile の設定不備を検出するようになりました」

従来、 Dockerfile のスキャンといえば Trivy や Dockle のイメージでしたが、ついに Amazon Inspector も参戦してきて面白くなってきました。このブログがどなたかの参考になれば幸いです。

AWS 事業本部コンサルティング部のたかくに(@takakuni_)でした!

この記事をシェアする

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.